import java.util.Arrays;
import java.util.Random;
public class Test {
    //测试各种情况下各种排序的速度快慢
    //有序
    public static void inorderSort(int[] array) {
        for(int i = 0;i < array.length;i++) {
            array[i] = i;
        }
    }
    //逆序
    public static void notInorderSort(int[] array) {
        for(int i = array.length - 1;i >= 0;i--) {
            array[i] = i;
        }
    }
    //乱序
    public static void initOrderSort(int[] array) {
        Random random = new Random();
        for(int i = 0;i < array.length;i++) {
            int num = random.nextInt();
            array[i] = num;
        }
    }
    public static void testInsertSort(int[] array) {
        int[] tmpArray = array;
        //计时
        long startTime = System.currentTimeMillis();
        //调用排序
        Sort.insertSort(tmpArray);
        long endTime = System.currentTimeMillis();
        System.out.println("直接插入排序: " + (endTime - startTime));
    }
    public static void testShellSort(int[] array) {
        int[] tmpArray = array;
        long startTime = System.currentTimeMillis();
        Sort.shellSort(tmpArray);
        long endTime = System.currentTimeMillis();
        System.out.println("希尔排序: " + (endTime - startTime));
    }
    public static void testSelectSort(int[] array) {
        int[] tmpArray = array;
        long startTime = System.currentTimeMillis();
        Sort.selectSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("选择排序: " + (endTime - startTime));
    }
    public static void testHeapSort(int[] array) {
        int[] tmpArray = array;
        long startTime = System.currentTimeMillis();
        Sort.heapSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("堆排序: " + (endTime - startTime));
    }
    public static void testQuickSort(int[] array) {
        int[] tmpArray = array;
        long startTime = System.currentTimeMillis();
        Sort.quickSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("快速排序: " + (endTime - startTime));
    }

    public static void testMergeSort(int[] array) {
        int[] tmpArray = array;
        long startTime = System.currentTimeMillis();
        Sort.mergeSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("归并排序: " + (endTime - startTime));
    }
    public static void main1(String[] args) {
        int[] array = new int[100000];
        //最好情况下,各个排序速度
        //inorderSort(array);
        // 逆序情况
        //notInorderSort(array);
        //乱序
        initOrderSort(array);

        testInsertSort(array);
        testShellSort(array);
        testSelectSort(array);
        testHeapSort(array);
        testQuickSort(array);
        testMergeSort(array);
    }
    public static void main(String[] args) {
        //int[] array = {1,3,6,2,5,4};
        int[] array = {1,2,3,5,5,2,2,1,4,6};
        //Sort.insertSort(array);
        //Sort.selectSort(array);
        //Sort.selectSort2(array);
        //Sort.heapSort(array);
        //Sort.bubbleSort(array);
//        Sort.quickSort(array);
        //Sort.quickSortNor(array);
        //Sort.mergeSort(array);
        //Sort.mergeSortNor(array);
        Sort.countSort(array);
        System.out.println(Arrays.toString(array));
    }
}
